#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    FILE *IN;
    IN = fopen("example.c", "r");
    if(IN == NULL) return 0;
    int tmp, line = 1, error = 0;
    char stack[200], save[200], linenum[1000];
    int p_to_stack = -1 , p_to_save = -1;
    for(;;)
    {
        tmp = fgetc(IN);
        if(tmp == EOF || error) break;
        else if(tmp == '\n')
            line++;
        else if(tmp == '"')
        {
            while (1)
            {
                tmp = fgetc(IN);
                if(tmp == '\\') tmp = fgetc(IN);
                else if(tmp == '"') break;
            }
        }
        else if(tmp == '\'')
        {
            while (1)
            {
                tmp = fgetc(IN);
                if(tmp == '\\') tmp = fgetc(IN);
                else if(tmp == '\'') break;
            }
        }
        else if(tmp =='/')
        {
            tmp = fgetc(IN);
            if(tmp == '/')
            {
                while((tmp = fgetc(IN)) != '\n');
                line++;
            }
            else if(tmp == '*')
            {
                int flag = 0;
                tmp = fgetc(IN);
                while(1)
                {
                    if(flag) break;
                    while(tmp != '*')
                    {
                        tmp = fgetc(IN);
                        if(tmp == '\n') line++;
                    }
                    tmp = fgetc(IN);
                    if(tmp == '\n') line++;
                    if(tmp =='/') flag = 1;
                }
            }
        }
        else if(tmp == '(')
        {
            stack[++p_to_stack] = tmp;
            save[++p_to_save] = tmp;
            linenum[p_to_stack] = line;
        }
        else if(tmp == '{')
        {
            save[++p_to_save] = tmp;
            if(stack[p_to_stack] == '(') //这里忘记了
            {
                error = 1;
                printf("without maching '(' at line %d\n", line); 
            }
            else
            {
                stack[++p_to_stack] = tmp;
                linenum[p_to_stack] = line;
            }
        }
        else if(tmp == ')')
        {
            save[++p_to_save] = tmp;
            linenum[p_to_stack] = line;
            if(stack[p_to_stack] == '(')
                p_to_stack--;
            else
            {
                error = 1;
                printf("without maching '%c' at line %d\n", tmp, line);
            }
        }
        else if(tmp == '}')
        {
            save[++p_to_save] = tmp;
            linenum[p_to_stack] = line;
            if(stack[p_to_stack] == '{')
                p_to_stack--;
            else
            {
                error = 1;
                printf("without maching '%c' at line %d\n", tmp, line);
            }
        }
        else continue;
    }
    if(!p_to_stack)
    {
        error = 1;
        printf("without maching '%c' at line %d\n", stack[p_to_stack], linenum[p_to_stack]);
    }
    save[++p_to_save] = '\0';
    if(!error) printf("%s", save);
    fclose(IN);
    return 0;
}